import * as copyAlias from 'copy-to-clipboard'
import { message } from 'antd'

export function useClipboard() {
  const copy = (text: string): Promise<void> => new Promise((resolve, reject) => {
    try {
      copyAlias(text)
      message.success('复制成功')
      resolve()
    } catch (error) {
      message.error('您的浏览器不支持剪贴板API')
      reject(new Error('Your browser does not support Clipboard API'))
    }
  })

  return { copy }
}
